package com.cwiyc.orderonlineback.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.cwiyc.orderonlineback.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;


@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select nickname from user where nickname=#{acc} and password=#{pas}")
    User login(String acc, String pas);

    @Insert("insert into user (nickname,password,phone,sex,type,avatar) values (#{acc},#{pas},#{phone},#{sex},#{type},#{avatar})")
    int register(String acc,String pas,String phone,Integer sex,Integer type,String avatar);

    @Update("update user set avatar=#{ava} where nickname=#{nic} ")
    int updateAva(String nic, String ava);

    @Select("select * from user where nickname=#{acc}")
    User getuser(String acc);

    @Insert("insert into emailvalidation (email,code,expiretime) values (#{email},#{code},#{expire})")
    int generateCode(String email, String code, Date expire);

    @Select("select email from emailvalidation where email=#{ema} and code=#{code} and type=#{type} expiretime>=#{expiretime}")
    String loginEmail(String ema, String code, Integer type, Date expiretime);

    @Select("select email from emailvalidation where email=#{ema} and code=#{code} and type=#{type} expiretime>=#{expiretime}")
    String regEmail(String ema, String code, Integer type, Date expiretime);

    @Select("select nickname from user where nickname=#{ema}")
    String searchIsExitByEmail(String ema);
}
